const baseUrl="https://api-hmugo-web.itheima.net/api";
let httpTimes=0
// 判断 ajax 的请求次数 如果全都请求完了 再 隐藏我们的loading弹框
const request=(params)=>{
  wx.showLoading({
    title: '加载中',
  })
  httpTimes++;
 return new Promise((resolve,reject)=>{
   wx.request({
     ...params,
     url:baseUrl+params.url,
     success:(res)=>{
       resolve(res.data.message)

     },
     fail:(err)=>{
       reject(err)
     },
     complete:()=>{
       httpTimes--
       if(httpTimes===0){
          wx.hideLoading()
       }
     
     }

   })

 })
}

export default request
